// 销售数据API接口
// import request from '@/utils/request'

// 简单的请求函数，替代request工具
const request = {
	get: (url, params) => {
		return new Promise((resolve) => {
			// 模拟API请求
			setTimeout(() => {
				resolve({ code: 200, data: null, message: 'success' });
			}, 500);
		});
	},
	post: (url, data) => {
		return new Promise((resolve) => {
			setTimeout(() => {
				resolve({ code: 200, data: null, message: 'success' });
			}, 500);
		});
	}
}

/**
 * 获取销售数据概览
 * @param {Object} params 查询参数
 * @param {string} params.area 区域
 * @param {string} params.timeType 时间类型：yesterday, week, month, quarter
 * @param {string} params.startDate 开始日期
 * @param {string} params.endDate 结束日期
 */
export function getSalesOverview(params) {
	return request({
		url: '/api/sales/overview',
		method: 'GET',
		params
	})
}

/**
 * 获取销售趋势数据
 * @param {Object} params 查询参数
 */
export function getSalesTrend(params) {
	return request({
		url: '/api/sales/trend',
		method: 'GET',
		params
	})
}

/**
 * 获取商品销售数据
 * @param {Object} params 查询参数
 */
export function getProductSales(params) {
	return request({
		url: '/api/sales/products',
		method: 'GET',
		params
	})
}

/**
 * 获取门店数据
 * @param {Object} params 查询参数
 */
export function getStoreData(params) {
	return request({
		url: '/api/sales/stores',
		method: 'GET',
		params
	})
}

/**
 * 获取区域列表
 */
export function getAreaList() {
	return request({
		url: '/api/common/areas',
		method: 'GET'
	})
}

/**
 * 获取商品品牌列表
 */
export function getBrandList() {
	return request({
		url: '/api/common/brands',
		method: 'GET'
	})
}

/**
 * 获取业务类型列表
 */
export function getBusinessTypes() {
	return request({
		url: '/api/common/business-types',
		method: 'GET'
	})
}

/**
 * 导出销售数据
 * @param {Object} params 导出参数
 */
export function exportSalesData(params) {
	return request({
		url: '/api/sales/export',
		method: 'POST',
		data: params,
		responseType: 'blob'
	})
}

/**
 * 获取销售数据详情列表
 * @param {Object} params 查询参数
 */
export function getSalesDetailList(params) {
	return request({
		url: '/api/sales/detail-list',
		method: 'GET',
		params
	})
}

// 模拟数据 - 开发阶段使用
export const mockData = {
	// 销售概览数据
	overview: {
		totalAmount: 156312.00,
		totalAmountTrend: 10,
		productSales: 12312.00,
		productSalesTrend: -10,
		newStores: 10,
		newStoresTrend: 10,
		monthlyPickup: 10,
		monthlyPickupTrend: 0,
		totalStores: 1150,
		totalStoresTrend: 10
	},
	
	// 趋势数据
	trend: {
		labels: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
		data: [189, 150, 348, 275, 290, 250, 270, 235, 242, 291, 238, 380]
	},
	
	// 区域列表
	areas: [
		{ id: 1, name: '朝阳区域', code: 'chaoyang' },
		{ id: 2, name: '海淀区域', code: 'haidian' },
		{ id: 3, name: '丰台区域', code: 'fengtai' },
		{ id: 4, name: '西城区域', code: 'xicheng' }
	],
	
	// 品牌列表
	brands: [
		{ id: 1, name: '品牌A', code: 'brand_a' },
		{ id: 2, name: '品牌B', code: 'brand_b' },
		{ id: 3, name: '品牌C', code: 'brand_c' },
		{ id: 4, name: '品牌D', code: 'brand_d' }
	],
	
	// 业务类型
	businessTypes: [
		{ id: 1, name: '零售', code: 'retail' },
		{ id: 2, name: '批发', code: 'wholesale' },
		{ id: 3, name: '代理', code: 'agency' },
		{ id: 4, name: '直营', code: 'direct' }
	],
	
	// 详情列表
	detailList: [
		{
			id: 1,
			icon: 'calendar',
			title: '在 12月 完成数量最多',
			desc: '数据指标在本年度的完成中',
			value: '12月',
			color: '#FFB74D'
		},
		{
			id: 2,
			icon: 'trending-up',
			title: '这个月卖出了 380件 羊奶粉',
			desc: '销售数据',
			value: '380件',
			color: '#4CAF50'
		},
		{
			id: 3,
			icon: 'person',
			title: '领先了 95.3% 的人员',
			desc: '排名情况',
			value: '95.3%',
			color: '#2196F3'
		}
	]
}

// 开发环境使用模拟数据
export function getMockSalesOverview(params) {
	return new Promise((resolve) => {
		setTimeout(() => {
			resolve({
				code: 200,
				data: mockData.overview,
				message: 'success'
			})
		}, 500)
	})
}

export function getMockSalesTrend(params) {
	return new Promise((resolve) => {
		setTimeout(() => {
			resolve({
				code: 200,
				data: mockData.trend,
				message: 'success'
			})
		}, 500)
	})
}

export function getMockAreaList() {
	return new Promise((resolve) => {
		setTimeout(() => {
			resolve({
				code: 200,
				data: mockData.areas,
				message: 'success'
			})
		}, 300)
	})
}

export function getMockBrandList() {
	return new Promise((resolve) => {
		setTimeout(() => {
			resolve({
				code: 200,
				data: mockData.brands,
				message: 'success'
			})
		}, 300)
	})
}

export function getMockBusinessTypes() {
	return new Promise((resolve) => {
		setTimeout(() => {
			resolve({
				code: 200,
				data: mockData.businessTypes,
				message: 'success'
			})
		}, 300)
	})
}

export function getMockSalesDetailList() {
	return new Promise((resolve) => {
		setTimeout(() => {
			resolve({
				code: 200,
				data: mockData.detailList,
				message: 'success'
			})
		}, 400)
	})
}
